﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace WorkTool
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		private DateTime LastSaved = DateTime.MinValue;
		private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new About().Show();
		}
		private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Options options = new Options();
			options.Show();
			DialogResult dr = options.DialogResult;


		}
		private void Form1_Load(object sender, EventArgs e)
		{
			Text = AssemblyTitle + " " + AssemblyVersion;
		}
		private void NoteTaker1_Save(object sender, EventArgs e)
		{
			lblStatus.Text = "Work saved";
			System.Threading.Thread.Sleep(100);
			LastSaved = DateTime.Now;
			lblStatus.Text = "Idle";
		}
		private void timer1_Tick(object sender, EventArgs e)
		{
			string saved = (DateTime.Now - LastSaved).ToString().Trim();
			if (saved.Length > 8) saved = saved.Substring(0, 8);
			if (LastSaved != DateTime.MinValue)
				lblLastSaved.Text = "Last Saved: " + saved + " ago";
		}
		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Application.Exit();
		}

		#region Assembly Attribute Accessors

		public string AssemblyTitle
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes.Length > 0)
				{
					AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
					if (titleAttribute.Title != "")
					{
						return titleAttribute.Title;
					}
				}
				return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
			}
		}

		public string AssemblyVersion
		{
			get
			{
				return Assembly.GetExecutingAssembly().GetName().Version.ToString();
			}
		}

		public string AssemblyDescription
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyDescriptionAttribute)attributes[0]).Description;
			}
		}

		public string AssemblyProduct
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyProductAttribute)attributes[0]).Product;
			}
		}

		public string AssemblyCopyright
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
			}
		}

		public string AssemblyCompany
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCompanyAttribute)attributes[0]).Company;
			}
		}
		#endregion

		private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch (tabControl2.SelectedTab.Text) {
				case "Lotus":
					AcceptButton = this.lotusTool1.btnOK;
					break;
				case "Hex":
					AcceptButton = this.hexConverter1.btnConvert;
					break;
				case "FileSearch":
					AcceptButton = this.fileSearcher1.btnSearch;
					break;
			}
		}
		private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch (tabControl1.SelectedTab.Text)
			{
				case "NoteTaker":
					saveToolStripMenuItem.Enabled = true;
					break;
				case "Small Tools":
					saveToolStripMenuItem.Enabled = false;
					switch (tabControl2.SelectedTab.Text)
					{
						case "Lotus":
							AcceptButton = this.lotusTool1.btnOK;
							this.lotusTool1.textBox2.Focus();
							break;
						case "Hex":
							AcceptButton = this.hexConverter1.btnConvert;
							break;
						case "FileSearch":
							AcceptButton = this.fileSearcher1.btnSearch;
							break;
					}
					break;
			}

		}
		private void saveToolStripMenuItem_Click(object sender, EventArgs e)
		{
			NoteTaker1.DoSaveFile();
		}
	
	}
}
